package com.annotation.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

@Component
public class TestBeanDefinationRegistoryPostProsser  implements BeanDefinitionRegistryPostProcessor {

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        System.out.println("testBeanDefinitionRegistry start...");
        System.out.println("testBeanDefinitionRegistry 注入beanDefinition之前："+beanDefinitionRegistry.getBeanDefinitionCount());
        BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(Oragin.class);
        beanDefinitionRegistry.registerBeanDefinition("Car", new  RootBeanDefinition(Car.class));
        beanDefinitionRegistry.registerBeanDefinition("Oragfin",beanDefinitionBuilder.getBeanDefinition());
        System.out.println("testBeanDefinitionRegistry 注入beanDefinition之后: " +beanDefinitionRegistry.getBeanDefinitionCount());
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

        System.out.println("testBeanDefinitionRegistry 调用 postProcessBeanFactory");
    }
}
